package com.mdd.system.provider;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.system.api.SystemConfigApi;
import com.mdd.system.entity.SystemConfig;
import com.mdd.system.mapper.SystemConfigMapper;
import com.mdd.system.vo.SystemConfigVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author 幻速
 * @Date 2024/3/19 11:53
 **/
@Service
public class SystemConfigApiProvider implements SystemConfigApi {
    @Resource
    SystemConfigMapper systemConfigMapper;
    @Override
    public List<SystemConfigVo> getSystemConfigs(String type) {
        List<SystemConfig> configs = systemConfigMapper.selectList(
                new QueryWrapper<SystemConfig>()
                        .select("id", "type", "name", "value")
                        .eq("type", type));
        List<SystemConfigVo> systemConfigVos=new ArrayList<>();
        configs.forEach(systemConfig -> {
            SystemConfigVo systemConfigVo=new SystemConfigVo();
            BeanUtil.copyProperties(systemConfig,systemConfigVo);
            systemConfigVos.add(systemConfigVo);
        });
        return systemConfigVos;
    }

    @Override
    public SystemConfigVo getSystemConfig(String name, String type) {
        SystemConfig systemConfig = systemConfigMapper.selectOne(new QueryWrapper<SystemConfig>()
                .eq("name", "appId")
                .eq("type", "oa_channel")
                .last("limit 1"));
        SystemConfigVo systemConfigVo=new SystemConfigVo();
        BeanUtil.copyProperties(systemConfig,systemConfigVo);
        return systemConfigVo;
    }
}
